package io.osw.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;
import java.util.Date;
import io.osw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


import io.osw.modules.sys.entity.TblPrBatchEntity;
import io.osw.modules.sys.service.TblPrBatchService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 采购申请批表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-10 21:27:18
 */
@RestController
@RequestMapping("sys/tblprbatch")
public class TblPrBatchController extends AbstractController{
    @Autowired
    private TblPrBatchService tblPrBatchService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblprbatch:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblPrBatchService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{batchId}")
    @RequiresPermissions("sys:tblprbatch:info")
    public R info(@PathVariable("batchId") Long batchId){
        TblPrBatchEntity tblPrBatch = tblPrBatchService.selectById(batchId);

        return R.ok().put("tblPrBatch", tblPrBatch);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblprbatch:save")
    public R save(@RequestBody TblPrBatchEntity tblPrBatch){
        tblPrBatch.setCreateTime(new Date());
        tblPrBatch.setCreateBy(getUser().getUserId());
        tblPrBatchService.insert(tblPrBatch);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblprbatch:update")
    public R update(@RequestBody TblPrBatchEntity tblPrBatch){
        ValidatorUtils.validateEntity(tblPrBatch);
        tblPrBatch.setUpdateTime(new Date());
        tblPrBatch.setUpdateBy(getUser().getUserId());
        tblPrBatchService.updateAllColumnById(tblPrBatch);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblprbatch:delete")
    public R delete(@RequestBody Long[] batchIds){
        tblPrBatchService.deleteBatchIds(Arrays.asList(batchIds));

        return R.ok();
    }

}
